package com.tanhua.server.controller;

import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VisitorsVo;
import com.tanhua.model.mongo.Movement;
import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/movements")
public class MovementController {
    @Autowired
   private MovementsService movementsService;

    @Autowired
    private CommentsService commentsService;

    /**
     * 圈子发布功能
     */
    @PostMapping
    public ResponseEntity movement(Movement movement, MultipartFile imageContent[]){
        movementsService.publishMovement(movement,imageContent);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/all")
    public ResponseEntity findByUserId(Long userId,@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = movementsService.findByUserId(userId,page,pagesize);

        return ResponseEntity.ok(pr);
    }

    /**
     * 查询好友动态列表
     */
    @GetMapping
    public ResponseEntity movements(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = movementsService.findFriendMovements(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查询推荐动态
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
      PageResult pr =  movementsService.findRecommendMovements(page,pagesize);
        return ResponseEntity.ok(pr);
    }


    /**
     * 单挑动态查询
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId){
     MovementsVo vo =  movementsService.findBymovementId(movementId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 点赞功能实现
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId){
     Integer likeCount =    commentsService.likeComment(movementId);
    return ResponseEntity.ok(likeCount);
    }

    /**
     * 取消点赞功能
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId){
        Integer likeCount =    commentsService.dislikeComment(movementId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态喜欢功能
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String movementId){
        Integer loveCount =    commentsService.loveComment(movementId);
        return ResponseEntity.ok(loveCount);
    }
    /**
     * 取消动态喜欢功能
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId){
        Integer unloveCount =    commentsService.disloveComment(movementId);
        return ResponseEntity.ok(unloveCount);
    }
    /**
     * 谁看过我
     */
    @GetMapping("/visitors")
    public ResponseEntity queryVisitorsList(){
        List<VisitorsVo> voList = movementsService.queryVisitorsList();
        return ResponseEntity.ok(voList);

    }


}
